<?php
	add_action('admin_init', 'create_coupon_metadata');

	function create_coupon_metadata()
	{
		// Get array event
		$tax_event = get_terms('event', array('hide_empty' => false));
		$arr_events = array(array('label' => 'None', 'value' => 'none'));
		foreach ($tax_event as $v)
		{
			$temp = array();
			$temp['label'] = $v->name;
			$temp['value'] = strtolower($v->name);
			array_push($arr_events, $temp);
		}
		// Get Stores
		$args = array(
			'post_type' => 'store',
			'post_status' => 'publish',
			'posts_per_page' => -1,
            'orderby'=>'title',
            'order'=>'ASC'
            );

		$stores = get_posts($args);
		$arr_stores = array();
		foreach ($stores as $v)
		{
			$t = array();
			$t['label'] = $v->post_title;
			$t['value'] = $v->ID;
			array_push($arr_stores, $t);
		}

		// Create metabox

		$coupon_type_meta_box = array(
			'id' => 'box_coupon_metadata',
			'title' => 'Coupon Meta Fields',
			'desc' => '',
			'pages' => array('coupon'),
			'context' => 'normal',
			'priority' => 'high',
			'fields' => array(
				// Coupon type
				array(
					'id' => 'coupon_type_metadata',
					'label' => 'Coupon type',
					'desc' => '',
					'std' => '',
					'type' => 'select',
					'class' => '',
					'choices' => array(
						array('label' => 'Coupon Code', 'value' => 'code')
                        )),
                // Exclusive or default
                array(
					'id' => 'exclusive_metadata',
					'label' => 'Exclusive',
					'desc' => '',
					'std' => '',
					'type' => 'radio',
					'class' => '',
					'choices' => array(array('label' => 'Default', 'value' => ''), array('label' => 'Exclusive',
								'value' => 1))),
				// If Coupon code : enter code
				array(
					'id' => 'coupon_code_metadata',
					'label' => 'Coupon code',
					'desc' => '',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// Expire date
				array(
					'id' => 'expire_date_metadata',
					'label' => 'Expire date',
					'desc' => 'yyyy/mm/dd',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// Like / Dislike
				array(
					'id' => 'like_metadata',
					'label' => 'Like',
					'desc' => '',
					'std' => 1,
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				array(
					'id' => 'dislike_metadata',
					'label' => 'Dislike',
					'desc' => '',
					'std' => 0,
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// Coupon rate
				array(
					'id' => 'cp_rate_metadata',
					'label' => 'Coupon rate (%)',
					'desc' => '',
					'std' => '',
					'type' => 'text',
					'class' => 'disable',
					'choices' => array()),
				// View
				array(
					'id' => 'coupon_view_metadata',
					'label' => 'View',
					'desc' => '',
					'std' => '1',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// Active / Deactive
				array(
					'id' => 'active_metadata',
					'label' => 'Active / Deactive',
					'desc' => '',
					'std' => 'active',
					'type' => 'radio',
					'class' => '',
					'choices' => array(array('label' => 'Active', 'value' => 'active'), array('label' => 'Deactive',
								'value' => 'deactive'))),
				// Event
				//			array(
				//				'id' => 'event_metadata',
				//				'label' => 'Select event',
				//				'desc' => '',
				//				'std' => 'none',
				//				'type' => 'radio',
				//				'class' => '',
				//				'choices' => $arr_events),
				// Store
				array(
					'id' => 'store_coupon_metadata',
					'label' => 'Select store',
					'desc' => '',
					'std' => '',
					'type' => 'select',
					'class' => '',
					'choices' => $arr_stores)));

		ot_register_meta_box($coupon_type_meta_box);

	}
?>